<template>
	<view class="body">
		<paper-left-popup :show="show" @clear='handleClearStorage' @hide='hidePopup()' @addfriend='handleAddFriend()'/>
		
		<!-- 小纸条列表 -->
		<block v-for="(item, index) in list" :key='index'>
			<paper-list :item="item" :index="index"/>
		</block>
		<load-more :loadtext="loadtext"/>
	</view>
</template>

<script>
	import PaperList from "../../components/paper/paper-list.vue"
	import LoadMore from '../../components/common/load-more.vue'
	import PaperLeftPopup from '../../components/paper/paper-left-popup.vue'
	export default {
		components:{
			PaperList,
			LoadMore,
			PaperLeftPopup
		},
		data() {
			return {
				show: false,
				loadtext: "上拉加载更多",
				list: [
					{
						userpic: "/static/demo/userpic/11.jpg",
						username: "昵称",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 0
					},
					{
						userpic: "/static/demo/userpic/11.jpg",
						username: "昵称",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 212
					},
					{
						userpic: "/static/demo/userpic/11.jpg",
						username: "昵称",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 1
					}
				]
			}
		},
		onPullDownRefresh() {
			this.inintData()
		},
		onReachBottom() {
			this.getMoreData()
		},
		onNavigationBarButtonTap(e) {
			switch(e.index) {
				case 0:
					this.hidePopup()
					uni.navigateTo({
						url:"/pages/user-list/user-list"
					})
				break;
				case 1:
					this.showPopup()
					console.log('点击右边显示操作单')
				break;
							
			}
		},
		methods: {
			
			// 初始化获取数据
			inintData() {
				let array =  [
					{
						userpic: "/static/demo/userpic/12.jpg",
						username: "猪猪猪仔",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 100
					},
					{
						userpic: "/static/demo/userpic/11.jpg",
						username: "hallo",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 0
					},
					{
						userpic: "/static/demo/userpic/13.jpg",
						username: "lizhixiong",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 112
					},
					{
						userpic: "/static/demo/userpic/12.jpg",
						username: "猪猪猪仔",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 100
					},
					{
						userpic: "/static/demo/userpic/11.jpg",
						username: "hallo",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 0
					},
					{
						userpic: "/static/demo/userpic/13.jpg",
						username: "lizhixiong",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 112
					},
					{
						userpic: "/static/demo/userpic/12.jpg",
						username: "猪猪猪仔",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 100
					},
					{
						userpic: "/static/demo/userpic/11.jpg",
						username: "hallo",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 0
					},
					{
						userpic: "/static/demo/userpic/13.jpg",
						username: "lizhixiong",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 112
					},{
						userpic: "/static/demo/userpic/12.jpg",
						username: "猪猪猪仔",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 100
					},
					{
						userpic: "/static/demo/userpic/11.jpg",
						username: "hallo",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 0
					},
					{
						userpic: "/static/demo/userpic/13.jpg",
						username: "lizhixiong",
						time: "20: 21",
						data: "我是信息啊",
						noreadnum: 112
					}
				]
				setTimeout(() => {
					this.list = array
					uni.stopPullDownRefresh()
				}, 2000)
			},
			// 上拉加载更多
			getMoreData() {
				if(this.loadtext != "上拉加载更多") return
				this.loadtext = "数据加载中...."
				
				setTimeout(()=>{
					this.list = this.list.concat(...this.list)
					this.loadtext = "上拉加载更多"
				},3000)
				
			},
			// 点击操作单添加好友
			handleAddFriend() {
				console.log('点击添加好友...')
				this.hidePopup()
			},
			// 点击操作单清除缓存
			handleClearStorage(){
				console.log('点击清除缓存...')
				this.hidePopup()
			},
			// 打开操作单和遮罩层
			showPopup(){
				this.show = true
			},
			// 关闭操作单和遮罩层
			hidePopup() {
				this.show = false
			}
		}
	}
</script>

<style scoped>
.body {
	padding: 0 20upx;
}

</style>
